<template>
	<div id="app">
		<el-card class="box-card" style="width: 800px;">
			<el-form ref="form" :model="username" label-width="80px" label-position='left'>
				<el-form-item label="姓名">
					<el-input style="width: 80px;" v-model="username.name"></el-input>
				</el-form-item>
				<el-form-item label="身份证号">
					<el-input style="width: 200px;" v-model="username.cardid"></el-input>
				</el-form-item>
				<el-form-item label="卡号">
					<el-input style="width: 200px;" v-model="username.idcard"></el-input>
				</el-form-item>
				<el-form-item label="电话">
					<el-input style="width: 200px;" v-model="username.tele"></el-input>
				</el-form-item>
				
				<el-form-item>
					<el-button type="primary" @click="updatagrzl">保存</el-button>
				</el-form-item>

			</el-form>
		</el-card>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				username: {
					username: '',
					tele: '',
					cardid: '',
					idcard: '',
					name: ''
				}
			}
		},
		methods: {
			GetUser() {
				console.log(sessionStorage.getItem("username"));
				if (sessionStorage.getItem("username") === null || sessionStorage.getItem("username") === '') {
					this.$message.error("请先登录");
					this.$router.push('/Login');
				} else {
					this.$http.get("http://localhost:8989/main/find", {
						params: {
							username: sessionStorage.getItem("username")
						}
					}).then(res => {
						console.log(res);
						if (res.data.status == null) {
							this.$message.error("请先登录");
							this.$router.push('/logon');
						} else {
							if (res.data.status == 0) {
								this.$message.error("请设置好自己的个人资料");
								this.username.username=sessionStorage.getItem("username");
							} else {
								this.username = res.data.data;
								sessionStorage.setItem(this.username.name, "name");
							}


						}
					}).catch(e => {
						console.log(e);
					})
				}

			},
			updatagrzl() {
				this.$http.post("http://localhost:8989/main/updata", this.username).then(res => {
					console.log(res);
					if (res.data.status == 0) {
						this.$message.error("保存失败");

					} else {
						this.$message.success("保存成功");
					}
				}).catch(e => {
					console.log(e);
				})

			}
		},
		created() {
			this.GetUser();

		}
	}
</script>

<style>
</style>
